// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
/*
 *      IP Virtual Server
 *      data structure and functionality definitions
 */

#ifndef _IP_VS_FNAT_H
#define _IP_VS_FNAT_H

#undef CONFIG_IP_VS_NFCT

#include <linux/types.h>	/* For __beXX types in userland */
#include <linux/netfilter.h>

#define IP_VS_VERSION_CODE	0x010201
#define NVERSION(version)			\
	(version >> 16) & 0xFF,			\
	(version >> 8) & 0xFF,			\
	version & 0xFF

/*
 *      Virtual Service Flags
 */
#define IP_VS_SVC_F_PERSISTENT	0x0001		/* persistent port */
#define IP_VS_SVC_F_HASHED	0x0002		/* hashed entry */
#define IP_VS_SVC_F_ONEPACKET	0x0004		/* one-packet scheduling */
#define IP_VS_SVC_F_SCHED1	0x0008		/* scheduler flag 1 */
#define IP_VS_SVC_F_SCHED2	0x0010		/* scheduler flag 2 */
#define IP_VS_SVC_F_SCHED3	0x0020		/* scheduler flag 3 */
#define IP_VS_SVC_F_TCPDRAINING 0x0040	/* tcp draining flag */
#define IP_VS_SVC_F_TCPDRAINING_TIMEOUT 0x0080	/* tcp draining timeoutflag */
#define IP_VS_SVC_F_FLOW_CONTROL_CPS 0x0100	/* flow_control_conps flag */
#define IP_VS_SVC_F_FLOW_CONTROL_PC 0x0200	/* flow_control_pc flag */
#define IP_VS_SVC_F_FLOW_CONTROL_CHANGE 0x0400	/* overflow config change */

#define IP_VS_SVC_F_SCHED_SH_FALLBACK	IP_VS_SVC_F_SCHED1 /* SH fallback */
#define IP_VS_SVC_F_SCHED_SH_PORT	IP_VS_SVC_F_SCHED2 /* SH use port */

#define IP_VS_SVC_F_OVF_CPS 0x0001	/* flow-control-conps  overflow flag */
#define IP_VS_SVC_F_OVF_PC 0x0002	/* flow-control-pc  overflow flag */
/*
 *      Destination Server Flags
 */
#define IP_VS_DEST_F_AVAILABLE	0x0001		/* server is available */
#define IP_VS_DEST_F_OVERLOAD	0x0002		/* server is overloaded */
#define IP_VS_DEST_F_TCP_DRAINING	0x0004	/* server in tcp_draining state*/

/*
 *      IPVS sync daemon states
 */
#define IP_VS_STATE_NONE	0x0000		/* daemon is stopped */
#define IP_VS_STATE_MASTER	0x0001		/* started as master */
#define IP_VS_STATE_BACKUP	0x0002		/* started as backup */

/*
 *      IPVS socket options
 */
#define IP_VS_BASE_CTL		(64 + 1024 + 64)		/* base */

#define IP_VS_SO_SET_NONE	IP_VS_BASE_CTL		/* just peek */
#define IP_VS_SO_SET_INSERT	(IP_VS_BASE_CTL + 1)
#define IP_VS_SO_SET_ADD	(IP_VS_BASE_CTL + 2)
#define IP_VS_SO_SET_EDIT	(IP_VS_BASE_CTL + 3)
#define IP_VS_SO_SET_DEL	(IP_VS_BASE_CTL + 4)
#define IP_VS_SO_SET_FLUSH	(IP_VS_BASE_CTL + 5)
#define IP_VS_SO_SET_LIST	(IP_VS_BASE_CTL + 6)
#define IP_VS_SO_SET_ADDDEST	(IP_VS_BASE_CTL + 7)
#define IP_VS_SO_SET_DELDEST	(IP_VS_BASE_CTL + 8)
#define IP_VS_SO_SET_EDITDEST	(IP_VS_BASE_CTL + 9)
#define IP_VS_SO_SET_TIMEOUT	(IP_VS_BASE_CTL + 10)
#define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL + 11)
#define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL + 12)
#define IP_VS_SO_SET_RESTORE    (IP_VS_BASE_CTL + 13)
#define IP_VS_SO_SET_SAVE       (IP_VS_BASE_CTL + 14)
#define IP_VS_SO_SET_ZERO	(IP_VS_BASE_CTL + 15)
#define IP_VS_SO_SET_ADDLADDR	(IP_VS_BASE_CTL + 16)
#define IP_VS_SO_SET_DELLADDR	(IP_VS_BASE_CTL + 17)
#define IP_VS_SO_SET_ADDCADDR		(IP_VS_BASE_CTL + 18)
#define IP_VS_SO_SET_DELCADDR		(IP_VS_BASE_CTL + 19)
#define IP_VS_SO_SET_EXCL_ADDCADDR	(IP_VS_BASE_CTL + 20)
#define IP_VS_SO_SET_EXCL_DELCADDR	(IP_VS_BASE_CTL + 21)
#define IP_VS_SO_SET_OVERLOAD_UP	(IP_VS_BASE_CTL + 22)
#define IP_VS_SO_SET_OVERLOAD_DOWN	(IP_VS_BASE_CTL + 23)
#define IP_VS_SO_SET_OVLD_DEFC_SWITCH   (IP_VS_BASE_CTL + 24)
#define IP_VS_SO_SET_VXLAN_PARAM        (IP_VS_BASE_CTL + 25)
#define IP_VS_SO_DEL_VXLAN_PARAM        (IP_VS_BASE_CTL + 26)
#define IP_VS_SO_SET_ADD_CHK_DEST	(IP_VS_BASE_CTL + 27)
#define IP_VS_SO_SET_DEL_CHK_DEST	(IP_VS_BASE_CTL + 28)
#define IP_VS_SO_SET_VLAN_FLAG          (IP_VS_BASE_CTL + 29)
#define IP_VS_SO_SET_HCK_DEST_FLUSH	(IP_VS_BASE_CTL + 30)
#define IP_VS_SO_SET_MAX		IP_VS_SO_SET_HCK_DEST_FLUSH

#define IP_VS_SO_GET_VERSION	IP_VS_BASE_CTL
#define IP_VS_SO_GET_INFO	(IP_VS_BASE_CTL + 1)
#define IP_VS_SO_GET_SERVICES	(IP_VS_BASE_CTL + 2)
#define IP_VS_SO_GET_SERVICE	(IP_VS_BASE_CTL + 3)
#define IP_VS_SO_GET_DESTS	(IP_VS_BASE_CTL + 4)
#define IP_VS_SO_GET_DEST	(IP_VS_BASE_CTL + 5)	/* not used now */
#define IP_VS_SO_GET_TIMEOUT	(IP_VS_BASE_CTL + 6)
#define IP_VS_SO_GET_DAEMON	(IP_VS_BASE_CTL + 7)
#define IP_VS_SO_GET_LADDRS	(IP_VS_BASE_CTL + 8)
#define IP_VS_SO_GET_OVERLOAD_LEVEL	(IP_VS_BASE_CTL + 9)
#define IP_VS_SO_GET_DESTS_EXT		(IP_VS_BASE_CTL + 10)
#define IP_VS_SO_GET_OVLD_DEFC_SWITCH	(IP_VS_BASE_CTL + 11)
#define IP_VS_SO_GET_VLAN_FLAG		(IP_VS_BASE_CTL + 12)
#define IP_VS_SO_GET_MAX		IP_VS_SO_GET_VLAN_FLAG


/*
 *      IPVS Connection Flags
 *      Only flags 0..15 are sent to backup server
 */
#define IP_VS_CONN_F_FWD_MASK	0x0007		/* mask for the fwd methods */
#define IP_VS_CONN_F_MASQ	0x0000		/* masquerading/NAT */
#define IP_VS_CONN_F_LOCALNODE	0x0001		/* local node */
#define IP_VS_CONN_F_TUNNEL	0x0002		/* tunneling */
#define IP_VS_CONN_F_DROUTE	0x0003		/* direct routing */
#define IP_VS_CONN_F_BYPASS	0x0004		/* cache bypass */
#define IP_VS_CONN_F_FULLNAT	0x0005		/* full nat */
#define IP_VS_CONN_F_NAT_IN_FULLNAT	0x0006
#define IP_VS_CONN_F_FULLNAT_IN_FULLNAT	0x0007
#define IP_VS_CONN_F_SYNC	0x0020		/* entry created by sync */
#define IP_VS_CONN_F_HASHED	0x0040		/* hashed entry */
#define IP_VS_CONN_F_NOOUTPUT	0x0080		/* no output packets */
#define IP_VS_CONN_F_INACTIVE	0x0100		/* not established */
#define IP_VS_CONN_F_OUT_SEQ	0x0200		/* must do output seq adjust */
#define IP_VS_CONN_F_IN_SEQ	0x0400		/* must do input seq adjust */
#define IP_VS_CONN_F_SEQ_MASK	0x0600		/* in/out sequence mask */
#define IP_VS_CONN_F_NO_CPORT	0x0800		/* no client port set yet */
#define IP_VS_CONN_F_TEMPLATE	0x1000		/* template, not connection */
#define IP_VS_CONN_F_ONE_PACKET	0x2000		/* forward only one packet */
#define IP_VS_CONN_F_DEFENCE    0x4000		/* forward to defence server */

/* Initial bits allowed in backup server */
#define IP_VS_CONN_F_BACKUP_MASK (IP_VS_CONN_F_FWD_MASK | \
				  IP_VS_CONN_F_NOOUTPUT | \
				  IP_VS_CONN_F_INACTIVE | \
				  IP_VS_CONN_F_SEQ_MASK | \
				  IP_VS_CONN_F_NO_CPORT | \
				  IP_VS_CONN_F_TEMPLATE \
				 )

/* Bits allowed to update in backup server */
#define IP_VS_CONN_F_BACKUP_UPD_MASK (IP_VS_CONN_F_INACTIVE | \
				      IP_VS_CONN_F_SEQ_MASK)

/* Flags that are not sent to backup server start from bit 16 */
#define IP_VS_CONN_F_NFCT	(1 << 16)	/* use netfilter conntrack */

/* Connection flags from destination that can be changed by user space */
#define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK | \
				IP_VS_CONN_F_ONE_PACKET | \
				IP_VS_CONN_F_NFCT | \
				0)

#define IP_VS_SCHEDNAME_MAXLEN	16
#define IP_VS_PENAME_MAXLEN	16
#define IP_VS_IFNAME_MAXLEN	16

#define IP_VS_PEDATA_MAXLEN     255

#define  MAX_ADDR_IP_LEN         (32)

/* Tunnel types */
enum {
	IP_VS_CONN_F_TUNNEL_TYPE_IPIP = 0,	/* IPIP */
	IP_VS_CONN_F_TUNNEL_TYPE_GUE,		/* GUE */
	IP_VS_CONN_F_TUNNEL_TYPE_GRE,		/* GRE */
	IP_VS_CONN_F_TUNNEL_TYPE_MAX,
};

/* Tunnel encapsulation flags */
#define IP_VS_TUNNEL_ENCAP_FLAG_NOCSUM		(0)
#define IP_VS_TUNNEL_ENCAP_FLAG_CSUM		(1 << 0)
#define IP_VS_TUNNEL_ENCAP_FLAG_REMCSUM		(1 << 1)

#define IP_VS_SYNCID_MAX        (1<<8)

#define IP_VS_DEVICENAME_MAXLEN  (16)

#define IP_VS_MAX_CADDR_NUM_PER_SVC	(2048)

/*
 *	The struct ip_vs_service_user and struct ip_vs_dest_user are
 *	used to set IPVS rules through setsockopt.
 */
struct ip_vs_service_user {
	/* virtual service addresses */
	__u16		protocol;
	__be32			addr;		/* virtual ip address */
	__be16			port;
	__u32		fwmark;		/* firwall mark of service */

	/* virtual service options */
	char			sched_name[IP_VS_SCHEDNAME_MAXLEN];
	unsigned int		flags;		/* virtual service flags */
	unsigned int		timeout;	/* persistent timeout in sec */
	__be32			netmask;	/* persistent netmask */
	unsigned int		overload_algorithm;	/* switch overload algorithm */
	__u32			subnet_id;    /* subnet id used, for vlan network */
	__u32			tcp_draining_timeout;	/* tcp_draining timeout in sec */
	__u32			fccps; /*flow-control-cps*/
	__u32			fctimeout; /*flow-control-times*/
	__u32			fcpc; /* flow-control-pc, number of parallel connections */
};

struct ip_vs_dest_user {
	/* destination server address */
	__be32			addr;
	__be16			port;

	/* real server options */
	unsigned int		conn_flags;	/* connection flags */
	int			weight;		/* destination weight */

	/* thresholds for active connections */
	__u32		u_threshold;	/* upper threshold */
	__u32		l_threshold;	/* lower threshold */
	char			oif_name[IP_VS_DEVICENAME_MAXLEN];    /* out interface name, for vlan network */
	u32			vni;
	u8			mac[MAX_ADDR_IP_LEN];
	union nf_inet_addr		vtepaddr;
	__be16				vtepport;
	bool					vxlan_private_flag_disable;
};

struct ip_vs_local_vtepinfo {
	union nf_inet_addr	vtepaddr;
	u16					lvs_index;
	u16					af;
	__u32				network_type;
	__u32				src_sen_routing;
};

struct ip_vs_laddr_user {	/* the local address struct */
	__be32		addr;		/* the ipv4 address */
	u8		port_type;       /* the specify the lan if */
	char			oif_name[IP_VS_DEVICENAME_MAXLEN];    /* out interface name, for vlan network */
};
struct ip_vs_caddr_user {
	__be32		addr;		/* ipv4 address */
	__u8		prefixlen;	/* The prefix length */
	__u32		expire;		/* expiration time */
};

struct ip_vs_overload_user {
	__u16		level;		/* overload level */
	__u16		rate;		/* filter rate */
};

/*
 *	IPVS statistics object (for user space)
 */
struct ip_vs_stats_user {
	__u64                   conns;          /* connections scheduled */
	__u64                   inpkts;         /* incoming packets */
	__u64                   outpkts;        /* outgoing packets */
	__u64                   inbytes;        /* incoming bytes */
	__u64                   outbytes;       /* outgoing bytes */

	__u64			cps;		/* current connection rate */
	__u64			inpps;		/* current in packet rate */
	__u64			outpps;		/* current out packet rate */
	__u64			inbps;		/* current in byte rate */
	__u64			outbps;		/* current out byte rate */
};

/* The argument to IP_VS_SO_GET_INFO */
struct ip_vs_getinfo {
	/* version number */
	unsigned int		version;

	/* size of connection hash table */
	unsigned int		size;

	/* number of virtual services */
	unsigned int		num_services;
};

/* The argument to IP_VS_SO_GET_SERVICE */
struct ip_vs_service_entry {
	/* which service: user fills in these */
	__u16		protocol;
	__be32			addr;		/* virtual address */
	__be16			port;
	__u32		fwmark;		/* firwall mark of service */

	/* service options */
	char			sched_name[IP_VS_SCHEDNAME_MAXLEN];
	unsigned int		flags;          /* virtual service flags */
	unsigned int		timeout;	/* persistent timeout */
	__be32			netmask;	/* persistent netmask */

	/* number of real servers */
	unsigned int		num_dests;

	/* number of allowed client address*/
	unsigned int		num_caddrs;

	/* number of excluded client address*/
	unsigned int		num_excl_caddrs;

	/* statistics */
	struct ip_vs_stats_user stats;
	__u32			subnet_id;  /* subnet id, for vlan network */
	__u32			num_laddrs;	/* number of local address */
	__u32 			tcp_draining_timeout;	/* tcp_draining timeout in sec */
	__u32			fccps; /*flow-control-cps*/
	__u32			fctimeout; /*flow-control-times*/
	__u32			fcpc; /* flow-control-pc, number of parallel connections */
};

struct ip_vs_dest_entry {
	__be32			addr;		/* destination address */
	__be16			port;
	unsigned int		conn_flags;	/* connection flags */
	int			weight;		/* destination weight */

	__u32		u_threshold;	/* upper threshold */
	__u32		l_threshold;	/* lower threshold */

	__u32		activeconns;	/* active connections */
	__u32		inactconns;	/* inactive connections */
	__u32		persistconns;	/* persistent connections */

	/* statistics */
	struct ip_vs_stats_user stats;
	__u32		defence;		/* the defence server flag */
	__be32		vtepaddr;		/* the destination address */
	__be16		vtepport;
	__u32		vni;
	u8			mac[MAX_ADDR_IP_LEN];
};

struct ip_vs_laddr_entry {	/* the local address */
	__be32 addr;		/* the ipv4 address */
	__u64 port_conflict;	/* the conflict counts */
	__u32 conn_counts;	/* the current connects */
};

/* The argument to IP_VS_SO_GET_DESTS */
struct ip_vs_get_dests {
	/* which service: user fills in these */
	__u16		protocol;
	__be32			addr;		/* virtual address */
	__be16			port;
	__u32		fwmark;		/* firwall mark of service */

	/* number of real servers */
	unsigned int		num_dests;

	/* the real servers */
	struct ip_vs_dest_entry	entrytable[0];
	__u32       subnet_id;  /* subnet id, only in vlan network */
};

struct ip_vs_get_laddrs {	/* the get local addrs */
	__u16 protocol;		/* which service: user fills in these */
	__be32 addr;		/* the virtual address */
	__be16 port;		/* the virtual port */
	__u32 fwmark;		/* the firwall mark of service */
	__u32 subnet_id;    /* subnet id, only in vlan network */
	__u32 num_laddrs;	/* number of local address */
	struct ip_vs_laddr_entry entrytable[0];	/* the real servers */
};

/* The argument to IP_VS_SO_GET_SERVICES */
struct ip_vs_get_services {
	/* number of virtual services */
	unsigned int		num_services;

	/* service table */
	struct ip_vs_service_entry entrytable[0];
};

/* The argument to IP_VS_SO_GET_TIMEOUT */
struct ip_vs_timeout_user {
	int			tcp_timeout;
	int			tcp_fin_timeout;
	int			udp_timeout;
};

/* The argument to IP_VS_SO_GET_DAEMON */
struct ip_vs_daemon_user {
	/* sync daemon state (master/backup) */
	int			state;

	/* multicast interface name */
	char			mcast_ifn[IP_VS_IFNAME_MAXLEN];

	/* SyncID we belong to */
	int			syncid;
};

/* The argument to IP_VS_SO_GET_OVERLOAD_LEVEL */
struct ip_vs_get_overload {
	/* which service: user fills in these */
	__u16           protocol;
	__be32          addr;           /* virtual address */
	__be16          port;
	__u32           fwmark;         /* firwall mark of service */

	__u16           level;
	__u16           rate;
};

/* The switch states */
struct ip_vs_switch {
	int mode;
	int sw_status;
};

/**
 *
 * IPVS Generic Netlink interface definitions
 *
 */

/* Generic Netlink family info */

#define IPVS_GENL_NAME		"IPVS"
#define IPVS_GENL_VERSION	0x1

struct ip_vs_flags {
	__u32 flags;
	__u32 mask;
};

/* Overload algorithm*/
enum {
	HALF_DEC = 0,
	PERCENT_DEC,
};

/* Defence mode */
enum {
	BLKWHTLST = 0,
	OVLD_DEFC,
};

/* Generic Netlink command attributes */
enum {
	IPVS_CMD_UNSPEC = 0,

	IPVS_CMD_NEW_SERVICE,		/* add service */
	IPVS_CMD_SET_SERVICE,		/* modify service */
	IPVS_CMD_DEL_SERVICE,		/* delete service */
	IPVS_CMD_GET_SERVICE,		/* get service info */

	IPVS_CMD_NEW_DEST,		/* add destination */
	IPVS_CMD_SET_DEST,		/* modify destination */
	IPVS_CMD_DEL_DEST,		/* delete destination */
	IPVS_CMD_GET_DEST,		/* get destination info */

	IPVS_CMD_NEW_DAEMON,		/* start sync daemon */
	IPVS_CMD_DEL_DAEMON,		/* stop sync daemon */
	IPVS_CMD_GET_DAEMON,		/* get sync daemon status */

	IPVS_CMD_SET_CONFIG,		/* set config settings */
	IPVS_CMD_GET_CONFIG,		/* get config settings */

	IPVS_CMD_SET_INFO,		/* only used in GET_INFO reply */
	IPVS_CMD_GET_INFO,		/* get general IPVS info */

	IPVS_CMD_ZERO,			/* zero all counters and stats */
	IPVS_CMD_FLUSH,			/* flush services and dests */

	IPVS_CMD_NEW_LADDR,
	IPVS_CMD_DEL_LADDR,
	IPVS_CMD_GET_LADDR,

	IPVS_CMD_NEW_CADDR,		/* add client addr to allowed client list */
	IPVS_CMD_DEL_CADDR,		/* delete client addr from allowed client list */
	IPVS_CMD_NEW_EXCL_CADDR,	/* add excluded client addr to excluded client list */
	IPVS_CMD_DEL_EXCL_CADDR,	/* delete excluded client addr from excluded client list */

	IPVS_CMD_OVERLOAD_UP,		/* increase the overload level by one */
	IPVS_CMD_OVERLOAD_DOWN,		/* decrease the overload level by one */
	IPVS_CMD_GET_OVERLOAD_LEVEL,	/* get the overload level */

	IPVS_CMD_SET_LOCAL_VXLAN,	/* the add local vxlan param */
	IPVS_CMD_DEL_LOCAL_VXLAN,	/* the add local vxlan param */
	IPVS_CMD_NEW_CHK_DEST,		/* the add health check destination */
	IPVS_CMD_DEL_CHK_DEST,		/* the del health check destination */
	IPVS_CMD_HCK_DEST_FLUSH,		/* flush health check dest */
	__IPVS_CMD_MAX,
};

#define IPVS_CMD_MAX (__IPVS_CMD_MAX - 1)

/* Attributes used in the first level of commands */
enum {
	IPVS_CMD_ATTR_UNSPEC = 0,
	IPVS_CMD_ATTR_SERVICE,		/* nested service attribute */
	IPVS_CMD_ATTR_DEST,		/* nested destination attribute */
	IPVS_CMD_ATTR_DAEMON,		/* nested sync daemon attribute */
	IPVS_CMD_ATTR_TIMEOUT_TCP,	/* TCP connection timeout */
	IPVS_CMD_ATTR_TIMEOUT_TCP_FIN,	/* TCP FIN wait timeout */
	IPVS_CMD_ATTR_TIMEOUT_UDP,	/* UDP timeout */
	IPVS_CMD_ATTR_LADDR,           /* local address */
	IPVS_CMD_ATTR_CADDR,            /* nested client address attribute */
	IPVS_CMD_ATTR_VXLAN,		/*vxlan param*/
	IPVS_CMD_ATTR_HCK_DEST,	/*vxlan health check dest*/
	IPVS_CMD_ATTR_VLAN_FLAG,    /* vlan network flag */
	__IPVS_CMD_ATTR_MAX,
};

#define IPVS_CMD_ATTR_MAX (__IPVS_CMD_ATTR_MAX - 1)

/*
 * Attributes used to describe a service
 *
 * Used inside nested attribute IPVS_CMD_ATTR_SERVICE
 */
enum {
	IPVS_SVC_ATTR_UNSPEC = 0,
	IPVS_SVC_ATTR_AF,		/* address family */
	IPVS_SVC_ATTR_PROTOCOL,		/* virtual service protocol */
	IPVS_SVC_ATTR_ADDR,		/* virtual service address */
	IPVS_SVC_ATTR_PORT,		/* virtual service port */
	IPVS_SVC_ATTR_FWMARK,		/* firewall mark of service */

	IPVS_SVC_ATTR_SCHED_NAME,	/* name of scheduler */
	IPVS_SVC_ATTR_FLAGS,		/* virtual service flags */
	IPVS_SVC_ATTR_TIMEOUT,		/* persistent timeout */
	IPVS_SVC_ATTR_NETMASK,		/* persistent netmask */

	IPVS_SVC_ATTR_STATS,		/* nested attribute for service stats */

	IPVS_SVC_ATTR_PE_NAME,		/* name of ct retriever */
	IPVS_SVC_ATTR_STATS64,		/* nested attribute for service stats */

	IPVS_SVC_ATTR_EST_TIMEOUT,	/* establish timeout */
	IPVS_SVC_ATTR_TCP_DRAINING_TIMEOUT,	/* tcp_draining timeout */
	IPVS_SVC_ATTR_FLOW_CONTROL_CPS,	/* flow-control-cps */
	IPVS_SVC_ATTR_FLOW_CONTROL_TIMEOUT,	/* flow-control-times*/
	IPVS_SVC_ATTR_FLOW_CONTROL_PC,	/* flow-control-pc, number of parallel connections */
	IPVS_SVC_ATTR_OVERLOAD_ALGORITHM,	/* overload algorithm */
	IPVS_SVC_ATTR_SUBNET,    /* subnet id, only exist in vlan network */

	IPVS_SVC_ATTR_TIMEOUT_TCP,      /* svc TCP connection timeout */
	IPVS_SVC_ATTR_TIMEOUT_TCP_FIN,  /* svc TCP FIN wait timeout */
	IPVS_SVC_ATTR_TIMEOUT_UDP,      /* svc UDP timeout */
	__IPVS_SVC_ATTR_MAX,
};

#define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)

/*
 * Attributes used to describe a destination (real server)
 *
 * Used inside nested attribute IPVS_CMD_ATTR_DEST
 */
enum {
	IPVS_DEST_ATTR_UNSPEC = 0,
	IPVS_DEST_ATTR_ADDR,		/* real server address */
	IPVS_DEST_ATTR_PORT,		/* real server port */

	IPVS_DEST_ATTR_FWD_METHOD,	/* forwarding method */
	IPVS_DEST_ATTR_WEIGHT,		/* destination weight */

	IPVS_DEST_ATTR_U_THRESH,	/* upper threshold */
	IPVS_DEST_ATTR_L_THRESH,	/* lower threshold */

	IPVS_DEST_ATTR_ACTIVE_CONNS,	/* active connections */
	IPVS_DEST_ATTR_INACT_CONNS,	/* inactive connections */
	IPVS_DEST_ATTR_PERSIST_CONNS,	/* persistent connections */

	IPVS_DEST_ATTR_STATS,		/* nested attribute for dest stats */

	IPVS_DEST_ATTR_ADDR_FAMILY,	/* Address family of address */

	IPVS_DEST_ATTR_STATS64,		/* nested attribute for dest stats */

	IPVS_DEST_ATTR_TUN_TYPE,	/* tunnel type */

	IPVS_DEST_ATTR_TUN_PORT,	/* tunnel port */

	IPVS_DEST_ATTR_TUN_FLAGS,	/* tunnel flags */

	IPVS_DEST_ATTR_DEFENCE,		/* whether dest is defence server */
	IPVS_DEST_ATTR_VNI,		/* the VNI id */
	IPVS_DEST_ATTR_VTEPADDR,	/* the vtep addr */
	IPVS_DEST_ATTR_VTEPPORT, /* the vtep port */
	IPVS_DEST_ATTR_MAC,		/* the dest mac addr */
	IPVS_DEST_ATTR_VTEPADDR_AF,	/* the vtep addr af */
	IPVS_DEST_ATTR_VXLAN_FLAG_DISABLE,		/* vxlan private flag disable */
	IPVS_DEST_ATTR_OIF_NAME,    /* name of output interface */
	IPVS_DEST_ATTR_OIF_ID,      /* id of output interface */

	__IPVS_DEST_ATTR_MAX,
};

#define IPVS_DEST_ATTR_MAX (__IPVS_DEST_ATTR_MAX - 1)

enum {
	IPVS_ATTR_VXLAN_UNSPEC = 0,
	IPVS_ATTR_VXLAN_LVS_INDEX,      /* the lvs index*/
	IPVS_ATTR_VXLAN_LOCAL_VTEPADDR,  /* the local vtepaddr*/
	IPVS_ATTR_VXLAN_LOCAL_AF,
	IPVS_ATTR_VXLAN_LOCAL_SWITCH,
	IPVS_ATTR_VXLAN_SOURCE_SENSITIVE_ROUTING,
	__IPVS_ATTR_VXLAN_VTEP_MAX,
};
#define IPVS_ATTR_VXLAN_VTEP_MAX ((__IPVS_ATTR_VXLAN_VTEP_MAX) - 1)
enum {
	IPVS_ATTR_HCK_DEST_ATTR_UNSPEC = 0,
	IPVS_ATTR_HCK_DEST_ATTR_AF,
	IPVS_ATTR_HCK_DEST_ATTR_ADDR,
	IPVS_ATTR_HCK_DEST_ATTR_VNI,
	IPVS_ATTR_HCK_DEST_ATTR_VTEPADDR,
	IPVS_ATTR_HCK_DEST_ATTR_VTEPPORT,
	IPVS_ATTR_HCK_DEST_ATTR_MAC,
	IPVS_ATTR_HCK_DEST_VXLAN_FLAG_DISABLE,
	__IPVS_ATTR_HCK_DEST_ATTR_MAX,
};
#define IPVS_ATTR_HCK_DEST_ATTR_MAX ((__IPVS_ATTR_HCK_DEST_ATTR_MAX) - 1)

enum {
	IPVS_LADDR_ATTR_UNSPEC = 0,	/* the start */
	IPVS_LADDR_ATTR_ADDR = 1,
	IPVS_LADDR_ATTR_PORT_CONFLICT = 2,
	IPVS_LADDR_ATTR_CONN_COUNTS = 3,
	IPVS_LADDR_ATTR_OIF_NAME = 4,
	IPVS_LADDR_ATTR_OIF_ID = 5,
	__IPVS_LADDR_ATTR_MAX = 6,
};
#define IPVS_LADDR_ATTR_MAX (__IPVS_LADDR_ATTR_MAX - 1)	/* the Local addr attr max */
/*
 *  Attirbutes used to describe a client address in
 *  allowed client list and excluded list
 */
enum {
	IPVS_CADDR_ATTR_UNSPEC = 0,
	IPVS_CADDR_ATTR_AF,
	IPVS_CADDR_ATTR_ADDR,
	IPVS_CADDR_ATTR_PREFIX,
	__IPVS_CADDR_ATTR_MAX,
};

#define IPVS_CADDR_ATTR_MAX (__IPVS_CADDR_ATTR_MAX - 1)

/*
 * Attributes describing a sync daemon
 *
 * Used inside nested attribute IPVS_CMD_ATTR_DAEMON
 */
enum {
	IPVS_DAEMON_ATTR_UNSPEC = 0,
	IPVS_DAEMON_ATTR_STATE,		/* sync daemon state (master/backup) */
	IPVS_DAEMON_ATTR_MCAST_IFN,	/* multicast interface name */
	IPVS_DAEMON_ATTR_SYNC_ID,	/* SyncID we belong to */
	IPVS_DAEMON_ATTR_SYNC_MAXLEN,	/* UDP Payload Size */
	IPVS_DAEMON_ATTR_MCAST_GROUP,	/* IPv4 Multicast Address */
	IPVS_DAEMON_ATTR_MCAST_GROUP6,	/* IPv6 Multicast Address */
	IPVS_DAEMON_ATTR_MCAST_PORT,	/* Multicast Port (base) */
	IPVS_DAEMON_ATTR_MCAST_TTL,	/* Multicast TTL */
	__IPVS_DAEMON_ATTR_MAX,
};

#define IPVS_DAEMON_ATTR_MAX (__IPVS_DAEMON_ATTR_MAX - 1)

/*
 * Attributes used to describe service or destination entry statistics
 *
 * Used inside nested attributes IPVS_SVC_ATTR_STATS, IPVS_DEST_ATTR_STATS,
 * IPVS_SVC_ATTR_STATS64 and IPVS_DEST_ATTR_STATS64.
 */
enum {
	IPVS_STATS_ATTR_UNSPEC = 0,
	IPVS_STATS_ATTR_CONNS,		/* connections scheduled */
	IPVS_STATS_ATTR_INPKTS,		/* incoming packets */
	IPVS_STATS_ATTR_OUTPKTS,	/* outgoing packets */
	IPVS_STATS_ATTR_INBYTES,	/* incoming bytes */
	IPVS_STATS_ATTR_OUTBYTES,	/* outgoing bytes */

	IPVS_STATS_ATTR_CPS,		/* current connection rate */
	IPVS_STATS_ATTR_INPPS,		/* current in packet rate */
	IPVS_STATS_ATTR_OUTPPS,		/* current out packet rate */
	IPVS_STATS_ATTR_INBPS,		/* current in byte rate */
	IPVS_STATS_ATTR_OUTBPS,		/* current out byte rate */
	IPVS_STATS_ATTR_PAD,
	__IPVS_STATS_ATTR_MAX,
};

#define IPVS_STATS_ATTR_MAX (__IPVS_STATS_ATTR_MAX - 1)

/* Attributes used in response to IPVS_CMD_GET_INFO command */
enum {
	IPVS_INFO_ATTR_UNSPEC = 0,
	IPVS_INFO_ATTR_VERSION,		/* IPVS version number */
	IPVS_INFO_ATTR_CONN_TAB_SIZE,	/* size of connection hash table */
	__IPVS_INFO_ATTR_MAX,
};

#define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1)

struct ip_vs_conn_info {
        __be16                  cport;
        __be16                  dport;
        __be16                  vport;
        __be16                  lport;
        u16                     af;             /* address family */
        union nf_inet_addr      caddr;          /* client address */
        union nf_inet_addr      vaddr;          /* virtual address */
        union nf_inet_addr      daddr;          /* destination address */
        union nf_inet_addr      laddr;          /* local address */
};

typedef void (*origin_conn_func)(struct ip_vs_conn_info *conn_info);

/*
 * Register hook function used to get original connect info
 * @pf: function that process connect info
 * 		Make sure pf do the following:
 * 		1. There's no sleep or scheduling function in it.
 * 		2. For performance, ensure that there are no time-consuming functions in it.
 * 		3. If do time-consuming things like write file, asynchronous is recommended, like kthread.
 * 		4. Must register legal hook function and unregister hook function when not using it.
 */
int __must_check register_get_origin_conn_func(origin_conn_func pf);
/* Unregister hook function used to get original connect info */
int __must_check unregister_get_origin_conn_func(void);

#endif	/* _IP_VS_H */
